// pages/QualityControl/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    menuItems: [
      {
        text: "执行质控",
        path: "executeControl",
        power: "3zhzk_xz",
        icon: "./img/execute.png"
      },
      {
        text: "质控记录",
        path: "controlRecord",
        power: "3zhzk_ck",
        icon: "./img/log.png"
      },
      {
        text: "自定义质控项",
        path: "definQuality",
        power: "3zhzk_zdyzkx",
        icon: "./img/normal.png"
      },
      {
        text: "质控设备管理",
        path: "equipmentManage",
        power: "3zhzk_zksbgl",
        icon: "./img/equipCon.png"
      },
      {
        text: "测试权限",
        path: "spare",
        power: "aaaa",
        icon: "/assets/collect.png"
      },
    ],
    powerItem: [],
  },
  // 页面权限
  powerJuge(arr) {
    let powerItem = wx.getStorageSync('power');
    //powerItem = ',' + powerItem + ',';
    let temp = arr.filter((item) => {
      let power = item.power;
      //let power = ',' + item.power + ',';
      if (powerItem.indexOf(power) > -1) {
        return item
      }
    })
    console.log(temp)
    return temp
  },
  // 按钮权限
  hasPower(power) {
    let hasItems = this.Store.getItem('power');
    if (typeof hasItems == 'undefined') {
      // 未设置权限时，默认开启所有权限
      return true
    }
    if (hasItems == '') {
      return false
    }
    hasItems = ',' + hasItems + ','
    if (hasItems.indexOf(',' + power + ',') != -1) return true
    return false
  },
  toPage(e) {
    let path = e.currentTarget.dataset.path;
    this.Router.push(path);
    console.log(e, '权限')
  },
  toExecute() {
    this.Router.push('executeControl')
  },
  toredcord() {
    this.Router.push('controlRecord')
  },
  tordefine() {
    this.Router.push('definQuality')
  },
  tordemanage() {
    this.Router.push('equipmentManage')
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let item = this.data.menuItems
    let temp = this.powerJuge(item)
    this.setData({
      powerItem: temp
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      let tempArr = this.getTabBar().data.itemMenu
      let index = tempArr.findIndex((item) => {
        if (item.power == '3zhzk') {
          return true
        }
      })
      console.log(index, '索引')
      this.getTabBar().setData({
        selected: index
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})